﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace SAFPodcast.WP8.Fwk.Converter
{
    public class UriConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var uri = value as Uri;
            var result = String.Empty;
            if (uri != null)
            {
                result = uri.ToString();
            }

            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            String text = value as String;
            Uri result = null;
            Uri.TryCreate(text, UriKind.Absolute, out result);

            return result;
        }
    }
}
